const app = getApp()

var utils = require('../../utils/util.js')
var tongji = require('../../utils/tongji.js')
Page({
  data: {
    url: '',
  },

  onLoad: function(options) {
    let that = this;
    wx.request({
      url: app.urlData.getURL + "/index.php/Weshop/SApi/index/m/createwxaqrcode/key/" + app.urlData.key + "/wid/" + app.urlData.wid + "/sign/" + wx.getStorageSync('sign'),
      method: 'get',
      data: {
        share_id: wx.getStorageSync('user_id'),
      },
      success: (res) => {
        console.log(res);
        if(res.data.status == 1){
          that.setData({
            url: res.data.data
          })
          wx.showToast({
            title: '生成成功',
            icon:'none'
          })
        }else{
          wx.showToast({
            title: '生成失败',
            icon: 'none'
          })
        }
      },
    })
  },
  onShow: function() {
   
  },
  //保存
  download: function(e) {
    console.log(e)
    var imgSrc = this.data.url
    wx.downloadFile({
      url: imgSrc,
      success: function (res) {
        console.log(res);
        //图片保存到本地
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function (data) {
            wx.showToast({
              title: '保存成功！',
              iconL:"success",
              duration:1600
            })
          },
          fail: function (err) {
            console.log(err);
            wx.showToast({
              title: '保存失败，请再次尝试',
              iconL: "none",
              duration: 1600
            })
          }
        })
      }
    })
  }
})
